import { createApp } from "vue";
import App from "./App.vue";
import router from "@/router";
import store from "@/store";
import i18n from "@/plugins/i18n";
import api from "@/plugins/api";
import global from "@/plugins/global";
import { showLoading, hideLoading } from "@/hooks/useLoading";
import "uno.css";
import "animate.css";

const app = createApp(App);
app.config.globalProperties["STATIC_URL"] = "/";
app.use(store);
app.use(router);
app.use(i18n);
app.use(api);
app.use(global);
app.mount("#app").$nextTick(() => {
  postMessage({ payload: "removeLoading" }, "*");
  initElectronApi();
});

function initElectronApi() {
  window.electronAPI.setTitle(VITE_ENV.VITE_TITLE);
  window.electronAPI.useLoading((event, visible) => {
    if (visible) {
      showLoading();
    } else {
      hideLoading();
    }
  });
  window.electronAPI.useMessage((event, type, content) => {
    switch (type) {
      case "success":
        window.$message.success(content);
        break;
      case "warning":
        window.$message.warning(content);
        break;
      case "info":
        window.$message.info(content);
        break;
      case "error":
        window.$message.error(content);
        break;
      case "loading":
        window.$message.loading(content);
        break;
    }
  });
}
